<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/12
 * Time: 9:34
 */
namespace Admin\Controller;
header("Content-Type:text/html;charset=utf-8");

use Admin\Model\B2cModel;
use Common\Controller\AuthController;
use Think\Model;

class UserController extends AuthController {

    public function user_list(){
        $p = I('p')?I('p'):1;
        $obj = D('B2c');
        $count = $obj->table('tb_company')->count();
        $Page= new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();
        $res = $obj->table('tb_company')->page($p,20)->select();
        $this->assign('show',$show);
        $this->assign('res',$res);
        $this->display();

    }

    public function research(){

        $p = I('p')?I('p'):1;
        $obj = D('B2c');
        $count = M('research')->count();
        $Page= new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();
        $res = M('research')->page($p,20)->select();
        foreach ($res as $key=>$value) {
            $res1 = D('B2c')->table('tb_company')->where(['ComID'=>$value['uid']])->getField('Name');
            /*echo $res1;*/

            $res[$key]['company']=$res1;
        }
        $this->assign('show',$show);
        $this->assign('res',$res);
        $this->display();

    }


    public function research_edit(){

        $id = I('id');
        if (!$id || !is_numeric($id)) {
            $this->error('参数不合法');
        }
        $res = M('research')->where(['id'=>$id])->find();
        if (!$res) {
            $this->error('报表不存在!');
        }
        $this->assign('res',$res);
        $this->display();

    }

    public function research_del(){
        $id = I('id');
        if (!$id || !is_numeric($id)) {
            $this->error('参数不合法');
        }
        $res = M('research')->where(['id'=>$id])->find();
        if (!$res) {
            $this->error('报表不存在!');
        }{
            $res1 = M('research')->where(['id'=>$id])->delete();
            if ($res1) {
                $this->redirect('research');
            }
        }     
    }

    public function research_edit_run(){

        if (!IS_AJAX) {
            $this->error('提交方式有误');
        }

        $res = M('research')->save($_POST);
        if ($res) {
            $this->success('修改成功',U('research'),0);
        }else {
            $this->error('修改失败');
        }

    }


}
